
def l59(n):
    res =[[0 for _ in range(n)] for _ in range(n)]
    print(res)
    num = 0
    row = 0
    col = 0
    # 0 1 2 3   0 4
    # 1 2       1 3
    while num < n*n:
        # 第row行 赋值
        if num == n*n-1 :
            num += 1
            res[row][col] = num
            break
        len1 = n -1 - row
        for i in range(row,len1):
            num += 1
            res[row][i] = num
        # 按列赋值，第col列赋值 num
        for j in range(col,len1):
            num += 1
            res[j][len1] = num
        for i in range(len1,col,-1):
            num += 1
            res[len1][i] = num
        for j in range(len1,col,-1):
            num += 1
            res[j][col] = num
        row += 1
        col += 1
    return res
    pass



if __name__ == '__main__':
    res = [[1, 2, 3, 4, 5], [16, 17, 18, 19, 6], [15, 24, 25, 20, 7], [14, 23, 22, 21, 8], [13, 12, 11, 10, 9]]

    print(l59(5))
    pass